﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Learning.Classifiers
{

    public class Tree_Node
    {
        public ArrayList m_Att_in_use;
        public List<Attribute_Stats> m_stats;
        public List<int> m_data_ptr_lst;

        Model_Tree m_model;

        public Model_Tree getModel()
        {
            return m_model;
        }

        public void setModel(Model_Tree model)
        {
            if (model == null) throw new Exception (" cannot set null model");
            m_model = model;
        }

        public Tree_Node()
        {
            m_data_ptr_lst = new List<int>();
            m_Att_in_use = new ArrayList();
            //m_stats = new List<Attribute_Stats>();
            m_childs = null;
            m_father = null;
            m_leaf_Val = -1;//%??
        }

        Tree_Node m_father;
        public void Set_father(Tree_Node father)
        {
            m_father = father;
        }

        public Tree_Node Get_father( )
        {
           return m_father;
        }

        int m_leaf_Val = -1;

        public int get_leaf_Val()
        {
            return m_leaf_Val;
        }
        public void set_leaf_Val(int value)
        {
            if (m_childs != null && value != -1) throw new Exception("cannot set leaf if it has childs");
            m_leaf_Val=value;
        }

        Tree_Node[] m_childs=null;
        public void set_Child_Num()
        {
            if (m_leaf_Val != -1) throw new Exception("canot set leaf, it has childs");
            if(m_childs!=null) throw new Exception("cannot overwrite childnumber");
            if (m_Att_in_use.Count < 1) throw new Exception("cannot set child number if it has not att");
            Chosen_Attribute tmp = (Chosen_Attribute)m_Att_in_use[m_Att_in_use.Count - 1];
            m_childs = new Tree_Node[(tmp.Get_att()).Num_of_vals];
        }

        public void set_Child_at(int where, Tree_Node what)
        {
            if (m_leaf_Val != -1) throw new Exception("this is a leaf node");
            m_childs[where] = what;
        }

        public Tree_Node get_Child_at(int where)
        {
            if (m_leaf_Val != -1) throw new Exception("this is a leaf node");
            return m_childs[where];
        }

        public int get_child_number()
        {
            return m_childs.Length;
        }
    }
}
